package com.kehutong.payfees.service.treasure;

//import com.kehutong.payfees.entity.treasure.OrganTempSeal;
//import com.kehutong.payfees.util.ESignTreasureUrlConfig;
//import org.coraframework.inject.Inject;
//import org.coraframework.json.JSONObject;
//import org.coraframework.mvc.webservice.WebService;
//import org.coraframework.orm.Pool;
//import org.coraframework.orm.jdbc.SQLSession;
//import org.coraframework.util.Objects;
//
//@WebService("/sign/treasure/personal/seal")
//public class ESignTreasureOrganTempSealServiceImpl{
//
//    @Inject
//    protected SQLSession jdbcSession;
//
//    @Inject
//    private ESignTreasureOAuthServiceImpl eSignTreasureOAuthService;
//
//    @Inject
//    private ESignTreasureUrlConfig eSignTreasureUrlConfig;
//
//    public Object pageOrganTempSeal(JSONObject jsonObject) {
//        return jdbcSession.findPage(OrganTempSeal.class)
//                .eq(jsonObject,  "alias", "orgName")
//                .eq("deleted", false)
//                .page(jsonObject).exe();
//    }
//
//    public void createOrganTempSeal(OrganTempSeal organTempSeal) throws Exception {
//        JSONObject jsonObject = eSignTreasureUrlConfig.postESignTreasure("/v1/organizations/" + organTempSeal.getOrgId() + "/seals/officialtemplate", (http) -> {
//            JSONObject bodyParams = new JSONObject();
//            bodyParams.put("alias", organTempSeal.getAlias());
//            bodyParams.put("color", organTempSeal.getColor());
//            if (Objects.nonEmpty(organTempSeal.getHtext())) {
//                bodyParams.put("htext", organTempSeal.getHtext());
//            }
//            if (Objects.nonEmpty(organTempSeal.getQtext())) {
//                bodyParams.put("qtext", organTempSeal.getQtext());
//            }
//            bodyParams.put("type", organTempSeal.getType());
//            bodyParams.put("central", organTempSeal.getCentral());
//            http.setBody(bodyParams.toString());
//
//            eSignTreasureOAuthService.setRequestHeaderValue(http);
//        });
//
//        String fileId = eSignTreasureOAuthService.getFileId(jsonObject.getString("url"), organTempSeal.getAlias() + ".png");
//        organTempSeal.setFileId(fileId);
//        organTempSeal.setFileKey(jsonObject.getString("fileKey"));
//        organTempSeal.setSealId(jsonObject.getString("sealId"));
//        jdbcSession.insert(organTempSeal);
//    }
//
//    public Object getOrganTempSeal(String id) {
//        return Pool.get(OrganTempSeal.class, id);
//    }
//
//    public void deleteOrganTempSeal(String orgId, String sealId) throws Exception {
//       eSignTreasureUrlConfig.delete("/v1/accounts/" + orgId + "/seals/" + sealId, (http) -> {
//            eSignTreasureOAuthService.setRequestHeaderValue(http);
//        });
//
//        OrganTempSeal organTempSeal = jdbcSession.findOne(OrganTempSeal.class)
//                .eq("sealId", sealId)
//                .eq("deleted", false).exe();
//        organTempSeal.setDeleted(true);
//        jdbcSession.updateById(organTempSeal);
//    }
//}
